package com.shiguiwu.springmybatis.spring.lifecycle.parse;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;

/**
 * @description: 解析阶段
 * @author: stone
 * @date: Created by 2021/3/21 18:41
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.spring.lifecycle.definition.parse
 */
public class XmlParseTests {

    public static void main(String[] args) {

        //定义一个spring容器，这个容器默认实现了BeanDefinitionRegistry，所以本身就是一个bean
        //注册器
        DefaultListableBeanFactory factory = new DefaultListableBeanFactory();

        //定义一个xml的BeanDefinition读取器，需要传递一个BeanDefinitionRegistry（bean注册器）对象
        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
        //通过XmlBeanDefinitionReader加载bean xml文件，然后将解析产生的BeanDefinition注册容器容器中
        int count = reader.loadBeanDefinitions("spring/user.xml");

        System.out.println("一共注册多少bean ===>" + count);

        for (String name : factory.getBeanDefinitionNames()) {
            //根据名称获取定义
            BeanDefinition beanDefinition = factory.getBeanDefinition(name);

            //根据具体哪个bean定义
            String className = beanDefinition.getClass().getName();

            //获取对象
            Object bean = factory.getBean(name);

            System.out.println(name +"===========================>");

            System.out.println("beanDefinition = " + beanDefinition);

            System.out.println("className = " + className);

            System.out.println("bean = " + bean);
        }




    }

}
